<?php
declare (strict_types = 1);
namespace app\common;

use think\App;
use think\Container;

/**
 * 服务层基类（此Service非TP框架中说的系统服务，主要用于管理可共用的业务逻辑）
 */
abstract class Service
{
    /**
     * 应用实例
     * @var App
     */
    protected $app;

    /**
     * 数据库操作实例
     * @var \think\Db
     */
    protected $db;

    /**
     * Service constructor.
     * @param App $app
     */
    public function __construct(App $app)
    {
        $this->app     = $app;
        $this->db = $this->app->db;
    }

    /**
     * 静态实例对象
     * @param array $var 实例参数
     * @param boolean $new 创建新实例
     * @return static
     */
    public static function instance(array $var = [], bool $new = false)
    {
        return Container::getInstance()->make(static::class, $var, $new);
    }
}